<template>
  <div class="search">
    <input type="text" class="black" :placeholder="props.placeholder" @keydown.enter="input" v-model="inputval">
    <span v-show="inputflag" class="cha">×</span>
    <Async_search_icon position="left" />
  </div>
</template>

<script setup>
import { ref, defineAsyncComponent } from 'vue'
const Async_search_icon = defineAsyncComponent(() => import('./icon/search-icon.vue'))
// input框的内容
const inputval = ref('')
const emit = defineEmits(['input'])
const props = defineProps({
  // 搜索的标题
  placeholder: {
    type: String,
    default: '搜索帖子'
  },
  inputflag: {
    type: Boolean
  }
}
)
// 回车提交
function input() {
  let params = {
    inputval: inputval.value
  }
  emit('input', params)
}

</script>

<style lang="scss" scoped>
.search {
  position: relative;
  display: flex;
  width: 92%;
  margin: auto;
  height: 44px;
  background: #242630;
  align-items: center;
  color: #fff;

  .black {
    border: 0;
    height: 30px;
    background: #242630;
    outline: none;
    margin-left: 40px;
    color: #e8e8e9;

    input {
      &::placeholder {
        font-size: 14px;
        color: #e8e8e9;
      }
    }
  }

  .cha {
    position: absolute;
    right: 0;
    top: 0;
    margin-top: 12px;
    margin-right: 10px;
    color: #fff;
    font-size: 16px;
  }
}
</style>